<template>

  <a-spin :spinning="confirmLoading">
    <a-row style="height: 525px">
      <a-row style="height: 90%">
        <a-col :span="24">
          <a-form :form="form" :hide-required-mark="true">
            <a-row :gutter="[16,8]">
              <a-col :span="10" align="center">
                <div style="margin: 0px auto">
                  <a-form-item :labelCol="labelCol" :wrapperCol="leftWrapperCol" label="选择车辆类型">
                    <a-select
                        style="width: 100px;"
                        v-decorator="['carTypeId', { rules: [{ required: true, message: '请选择车辆类型' }] }]"
                        @change="CarSelect"
                        :options="CarTypeSelect">
                    </a-select>
                  </a-form-item>
                  <a-form-item :labelCol="labelCol" :wrapperCol="leftWrapperCol" label="车场编号" v-show="false">
                    <p v-decorator="['parkCode', {initialValue:this.parkCode}]"></p>
                  </a-form-item>
                  <a-form-item :labelCol="labelCol" :wrapperCol="leftWrapperCol" label="车场名称" v-show="false">
                    <p v-decorator="['parkName', {initialValue:this.parkName}]"></p>
                  </a-form-item>
                  <a-form-item
                      :labelCol="labelCol"
                      :wrapperCol="leftWrapperCol"
                      label="每日最高收费限额（元）"
                      style="margin-bottom: 0px">
                    <a-input-number
                        :max="999"
                        style="width: 100px;"
                        :min="0"
                        v-decorator="['dayMoneyLimite', {initialValue:0}]">
                    </a-input-number>
                  </a-form-item>
                  <a-form-item
                      :labelCol="labelCol"
                      :wrapperCol="leftWrapperCol"
                      label="免费时间计费分钟"
                      style="margin-bottom: 0px">
                    <a-input-number
                        :max="999"
                        style="width: 100px"
                        :min="0"
                        v-decorator="['freeTime', {initialValue:0}]">
                    </a-input-number>
                  </a-form-item>
                  <a-form-item
                      :labelCol="labelCol"
                      :wrapperCol="leftWrapperCol"
                      label="启用免费时间"
                      style="margin-bottom: 0px">
                    <a-checkbox :checked="freeTimeStatus" @change="freeTimeStatusChange"></a-checkbox>
                  </a-form-item>
                  <a-form-item
                      :labelCol="labelCol"
                      :wrapperCol="leftWrapperCol"
                      label="分白天黑夜计费"
                      style="margin-bottom: 0px">
                    <a-checkbox :checked="ratesType" @change="ratesTypeChange"></a-checkbox>
                  </a-form-item>
                  <div>
                    <a-form-item
                        v-show="ratesType===true"
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="白天不满计时单位的停车时间"
                        style="margin-bottom: 0px">
                      <a-radio-group v-decorator="['dayTimeRemainderMode', {initialValue:'N'}]">
                        <a-row style="margin-top: 8px">
                          <a-col :span="12">
                            <a-radio :value="'N'">不计算</a-radio>
                          </a-col>
                          <a-col :span="12">
                            <a-radio :value="'Y'">计时数加一</a-radio>
                          </a-col>
                        </a-row>
                      </a-radio-group>
                    </a-form-item>
                    <a-form-item
                      v-show="ratesType===true"
                        :labelCol="labelCol"
                        :wrapperCol="wrapperCol"
                        label="夜晚不满计时单位的停车时间:"
                        style="margin-bottom: 0px">
                      <a-radio-group v-decorator="['nightTimeRemainderMode', {initialValue:'N'}]">
                        <a-row style="margin-top: 8px">
                          <a-col :span="12">
                            <a-radio :value="'N'">不计算</a-radio>
                          </a-col>
                          <a-col :span="12">
                            <a-radio :value="'Y'">计时数加一</a-radio>
                          </a-col>
                        </a-row>
                      </a-radio-group>
                    </a-form-item>
                    <a-form-item
                      v-show="ratesType===false"
                      :labelCol="labelCol"
                      :wrapperCol="wrapperCol"
                      label="不满计时单位的停车时间:"
                      style="margin-bottom: 0px">
                      <a-radio-group v-decorator="['timeRemainderMode', {initialValue:'N'}]">
                        <a-row style="margin-top: 8px">
                          <a-col :span="12">
                            <a-radio :value="'N'">不计算</a-radio>
                          </a-col>
                          <a-col :span="12">
                            <a-radio :value="'Y'">计时数加一</a-radio>
                          </a-col>
                        </a-row>
                      </a-radio-group>
                    </a-form-item>
                  </div>
                </div>
              </a-col>
              <a-col :span="4" style="height: 100%" align="center">
                <a-divider type="vertical" style="height: 200px;margin-top: 75px"></a-divider>
              </a-col>
              <a-col
                  :span="10"
                  v-show="ratesType"
                  style="height: 400px;overflow-y: auto"
                  align="center">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="白天计费设置"></a-form-item>
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="白天首计费收费额（元）">
                  <a-input-number
                      :max="999"
                      style="width: 100px"
                      :min="0"
                      v-decorator="['dayRegionFirstPrice', {initialValue:0}]">
                  </a-input-number>
                </a-form-item>
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="白天首计时单位分钟">
                  <a-select v-decorator="['dayRegionFirstUnitMin', {initialValue:FirstTimeSelect[2].value}]">
                    <a-select-option v-for="i in FirstTimeSelect" :key="i.value" :value="i.value">
                      {{ i.value }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="白天最高收费额（元）">
                  <a-input-number
                      :max="999"
                      style="width: 100px"
                      :min="0"
                      v-decorator="['dayRegionMaxPrice', {initialValue:0}]">
                  </a-input-number>
                </a-form-item>

                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="白天每计时单位收费额(元)">
                  <a-input-number
                      :max="999"
                      style="width: 100px"
                      :min="0"
                      v-decorator="['dayRegionUnitPrice', {initialValue:0}]">
                  </a-input-number>
                </a-form-item>
                <!--白天夜晚计时单位不同时，计费方式有误，暂时默认为60，不可更改                -->
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="白天计时单位分钟">
                  <a-select v-decorator="['dayRegionUnitMin', {initialValue:TimeSelect[1].value}]">
                    <a-select-option v-for="i in TimeSelect" :key="i.value" :value="i.value">
                      {{ i.value }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="区间白天开始时间">

                  <a-select
                      style="width: 100px"
                      v-model="dayStartTime"
                      @change="onDayTimeChange"
                      :options="DayTimeOptions"></a-select>

                </a-form-item>
                <a-form-item v-show="false" label="区间白天开始时间（小时）">
                  <a-input v-show="false" v-decorator="['dayRegionStartHour',{initialValue:'07'}]"></a-input>
                </a-form-item>
                <a-form-item v-show="false" label="区间白天开始时间（分）">
                  <a-input v-show="false" v-decorator="['dayRegionStartMin',{initialValue:'00'}]"></a-input>
                </a-form-item>

                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="夜间计费设置" style="margin-top: 5px">
                </a-form-item>
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="夜间首计费收费额（元）">
                  <a-input-number
                      :max="999"
                      style="width: 100px"
                      :min="0"
                      v-decorator="['nightRegionFirstPrice', {initialValue:0}]">
                  </a-input-number>
                </a-form-item>
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="夜间首计时单位分钟">
                  <a-select v-decorator="['nightRegionFirstUnitMin', {initialValue:FirstTimeSelect[2].value}]">
                    <a-select-option v-for="i in FirstTimeSelect" :key="i.value">
                      {{ i.value }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="夜间最高收费额（元）">
                  <a-input-number
                      :max="999"
                      style="width: 100px"
                      :min="0"
                      v-decorator="['nightRegionMaxPrice', {initialValue:0}]">
                  </a-input-number>
                </a-form-item>
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="夜间每计时单位收费额(元)">
                  <a-input-number
                      :max="999"
                      style="width: 100px"
                      :min="0"
                      v-decorator="['nightRegionUnitPrice', {initialValue:0}]">
                  </a-input-number>
                </a-form-item>
                <!--白天夜晚计时单位不同时，计费方式有误，暂时默认为60，不可更改                -->
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="夜间计时单位分钟">
                  <a-select v-decorator="['nightRegionUnitMin', {initialValue:TimeSelect[1].value}]">
                    <a-select-option v-for="i in TimeSelect" :key="i.value">
                      {{ i.value }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="区间黑夜开始时间">
                  <a-select
                      style="width: 100px"
                      v-model="nightStartTime"
                      @change="onNightTimeChange"
                      :options="NightTimeOptions"></a-select>
                </a-form-item>
                <a-form-item label="区间黑夜开始时间（小时）" v-show="false">
                  <a-input v-show="false" v-decorator="['nightRegionStartHour',{initialValue:'19'}]"></a-input>
                </a-form-item>
                <a-form-item v-show="false" label="区间黑夜开始时间（分）">
                  <a-input v-show="false" v-decorator="['nightRegionStartMin',{initialValue:'00'}]"></a-input>
                </a-form-item>
              </a-col>
              <a-col :span="10" style="height:400px" v-show="!ratesType" align="center">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="时间增量计费设置"></a-form-item>
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="计时单位（分钟）">
                  <a-select v-decorator="['timeUnit', {initialValue:TimeSelect[1].value}]">
                    <a-select-option v-for="i in TimeSelect" :key="i.value">
                      {{ i.value }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="每计时单位收费额（元）">
                  <a-input-number
                      :max="999"
                      style="width: 100px"
                      :min="0"
                      v-decorator="['moneyUnit', {initialValue:0}]">
                  </a-input-number>
                </a-form-item>
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="首计时单位（分钟）">
                  <a-select v-decorator="['firstUnit', {initialValue:FirstTimeSelect[2].value}]">
                    <a-select-option v-for="i in FirstTimeSelect" :key="i.value">
                      {{ i.value }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="首计时单位收费额（元）">
                  <a-input-number
                      :max="999"
                      style="width: 100px"
                      :min="0"
                      v-decorator="['firstMoney', {initialValue:0}]">
                  </a-input-number>
                </a-form-item>
              </a-col>
            </a-row>

            <a-col :gutter="18">
              <a-col :gutter="18">
                <a-col>
                  测试计费金额
                </a-col>
              </a-col>
              <a-col :md="6" :sm="6">
                <a-form-item>
                  <a-date-picker
                      :showTime="true"
                      format="YYYY-MM-DD HH:mm:ss"
                      value-format="YYYY-MM-dd HH:mm:ss"
                      placeholder="开始日期"
                      @change="onChangeStartTime"/>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="6">
                <a-form-item>
                  <a-date-picker
                      :showTime="true"
                      format="YYYY-MM-DD HH:mm:ss"
                      value-format="YYYY-MM-dd HH:mm:ss"
                      placeholder="结束日期"
                      @change="onChangeEndTime"
                      @ok="queryChargeFee"/>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="6">
                <a-form-item :labelCol="labelCol" label="计费结果（元）">
                  <a-input v-model="chargeFee" style="width: 100px" :value="0">
                  </a-input>
                </a-form-item>
              </a-col>
            </a-col>
          </a-form>
        </a-col>
      </a-row>
      <a-row style="height: 10%">
        <a-col style="width: 100%" align="center" type="flex">
          <a-button @click="$emit('currentChange',1)">
            上一步
          </a-button>
          <a-button style="margin-left: 25px" type="primary" @click="handleOk(true)">
            下一步
          </a-button>
          <a-button style="margin-left: 25px" type="primary" @click="handleOk(false)">
            确认设置
          </a-button>
        </a-col>
      </a-row>
    </a-row>
  </a-spin>
</template>

<script>
import {
  getAction,
  httpAction
} from '@/api/manage'
import pick from 'lodash.pick'
import moment from "moment"

export default {
  name: "ConfigParkChargeModal",
  data() {
    return {
      title: "操作",
      visible: false,
      model: {},
      labelCol: {
        xs: {
          span: 12
        },
        sm: {
          span: 12
        },
        style: 'textAlign: left',
      },
      leftWrapperCol: {
        xs: {
          span: 12
        },
        sm: {
          span: 12
        },
        style: 'textAlign: left',
      },
      wrapperCol: {
        xs: {
          span: 10
        },
        sm: {
          span: 10
        },
        style: 'textAlign: left',
        offset: 1
      },
      CarTypeSelect: [],
      TimeSelect: [
        {
          value: 30
        },
        {
          value: 60
        },
        {
          value: 120
        },
        {
          value: 180
        }
      ],
      FirstTimeSelect: [{value: 0}, {value: 10}, {value: 20}, {value: 30}, {value: 40}, {value: 50}, {value: 60}, {value: 70}, {value: 80}, {value: 90}, {value: 100}, {value: 110}, {value: 120},{value:180}],
      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {},
      url: {
        add: "/parking/configParkCharge/add",
        edit: "/parking/configParkCharge/edit",
        CarTypeList: "/ConfigCarType/configCarType/carTypeList",
        ParkChargeList: "/parking/configParkCharge/GetParkCharge",
        chargeFeeTest: "/parking/configParkCharge/testChargeFee"
      },
      ParkCarChargeConfig: [],
      parkCode: '',
      parkName: '',
      freeTimeStatus:true,
      ratesType:false,
      chargeFee: '',
      queryParam: {
        "carEnterTime": "",
        "carOutTime": "",
        "id": ""
      },
      dayStartTime: '7',
      nightStartTime: '19',
      DayTimeStart:null,
      NightTimeStart:null
    }
  },
  props: ['parkInfo'],

  computed: {
    DayTimeOptions: function () {
      var Array = []
      for (var i = 0; i < 19; i++) {
        Array.push({value: i, label: i})
      }
      return Array;
    },
    NightTimeOptions: function () {
      var Array = []
      for (var i = 19; i <= 23; i++) {
        Array.push({value: i, label: i})
      }
      return Array;
    }
  },
  mounted() {
    this.chargeEdit(this.parkInfo)
  },
  watch: {
    parkInfo() {
      this.chargeEdit(this.parkInfo)
    }
  },
  methods: {
    moment,
    add() {
      this.chargeEdit({});
    },
    chargeEdit(record) {
      this.EditCancel()
      const that = this
      this.confirmLoading = true
      this.visible = true
      this.parkCode = record.parkCode
      this.parkName = record.parkName
      this.form.resetFields();
      this.$nextTick(async () => {
        this.form.setFieldsValue(pick('parkCode', 'parkName', 'carTypeId'))
        this.form.setFieldsValue({
          parkCode: record.parkCode
        })
        this.form.setFieldsValue({
          parkName: record.parkName
        })

        await that.loadData()
        if (this.CarTypeSelect.length !== 0) {
          this.CarSelect(this.form.getFieldValue('carTypeId'))
        }
        //时间格式化
      });
    },
    close() {
      this.$emit('close');
      this.visible = false;
    },
    handleOk(model) {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!this.model.id) {
            httpurl += this.url.add;
            method = 'post';
          } else {
            httpurl += this.url.edit;
            method = 'put';
          }
          if (that.freeTimeStatus === false) {
            values.freeTimeStatus = 'N'
          } else {
            values.freeTimeStatus = 'Y'
          }
          if(that.ratesType === false)
          {
            values.ratesType = "0"
          }else {
            values.ratesType = "1"
          }
          values.firstMoney = values.firstMoney * 100
          values.moneyUnit = values.moneyUnit * 100
          values.dayMoneyLimite = values.dayMoneyLimite * 100
          values.dayRegionUnitPrice = values.dayRegionUnitPrice * 100
          values.dayRegionFirstPrice = values.dayRegionFirstPrice * 100
          values.dayRegionMaxPrice = values.dayRegionMaxPrice * 100
          values.nightRegionUnitPrice = values.nightRegionUnitPrice * 100
          values.nightRegionFirstPrice = values.nightRegionFirstPrice * 100
          values.nightRegionMaxPrice = values.nightRegionMaxPrice * 100
          let formData = Object.assign(this.model, values);
          //时间格式化
          formData.updateTime = formData.updateTime ? formData.updateTime.format('YYYY-MM-DD HH:mm:ss') : null;
          httpAction(httpurl, formData, method).then((res) => {
            if (res.success) {
              that.$message.success('设置成功');
              if (model === true) {
                that.$emit('currentChange', 3);
              } else {
                if (this.CarTypeSelect.length !== 0) {
                  this.CarSelect(this.form.getFieldValue('carTypeId'))
                }
              }
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }
      })
    },
    handleCancel() {
      this.close()
    },
    async loadParkData(value) {
      let that = this
      if (!this.url.ParkChargeList) {
        this.$message.error("请设置url.CarTypeList!")
        return
      }
      let params = {}
      params.parkCode = this.form.getFieldValue('parkCode')
      params.carTypeId = this.form.getFieldValue('carTypeId')

      //加载数据 若传入参数1则加载第一页的内容
      that.ParkCarChargeConfig = await httpAction(this.url.ParkChargeList, params, 'post').then((res) => {
        const arr = [];
        if (res.success) {
          res.result.forEach((car) => {
            arr.push(car)
          })
          return arr
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
          return
        }
      })
      if (that.ParkCarChargeConfig.length !== 0) {
        that.model.id = that.ParkCarChargeConfig[0].id
        that.ParkCarChargeConfig[0].firstMoney = that.ParkCarChargeConfig[0].firstMoney / 100
        that.ParkCarChargeConfig[0].moneyUnit = that.ParkCarChargeConfig[0].moneyUnit / 100
        that.ParkCarChargeConfig[0].dayMoneyLimite = that.ParkCarChargeConfig[0].dayMoneyLimite / 100
        that.ParkCarChargeConfig[0].dayRegionUnitPrice = that.ParkCarChargeConfig[0].dayRegionUnitPrice / 100
        that.ParkCarChargeConfig[0].dayRegionFirstPrice = that.ParkCarChargeConfig[0].dayRegionFirstPrice / 100
        that.ParkCarChargeConfig[0].dayRegionMaxPrice = that.ParkCarChargeConfig[0].dayRegionMaxPrice / 100
        that.ParkCarChargeConfig[0].nightRegionUnitPrice = that.ParkCarChargeConfig[0].nightRegionUnitPrice / 100
        that.ParkCarChargeConfig[0].nightRegionFirstPrice = that.ParkCarChargeConfig[0].nightRegionFirstPrice / 100
        that.ParkCarChargeConfig[0].nightRegionMaxPrice = that.ParkCarChargeConfig[0].nightRegionMaxPrice / 100
        that.dayStartTime = that.ParkCarChargeConfig[0].dayRegionStartHour;
        that.nightStartTime = that.ParkCarChargeConfig[0].nightRegionStartHour;
        that.form.setFieldsValue({
          carTypeId: value
        })
        that.form.setFieldsValue({
          freeTime: that.ParkCarChargeConfig[0].freeTime
        })
        that.form.setFieldsValue({
          dayMoneyLimite: that.ParkCarChargeConfig[0].dayMoneyLimite
        })
        that.freeTimeStatus = that.ParkCarChargeConfig[0].freeTimeStatus !== 'N';
        that.ratesType = Number(that.ParkCarChargeConfig[0].ratesType) !== 0;
        that.form.setFieldsValue({
          dayTimeRemainderMode: that.ParkCarChargeConfig[0].dayTimeRemainderMode
        })
        that.form.setFieldsValue({
          dayRegionUnitPrice: that.ParkCarChargeConfig[0].dayRegionUnitPrice
        })
        that.form.setFieldsValue({
          timeRemainderMode:that.ParkCarChargeConfig[0].timeRemainderMode
        })
        that.form.setFieldsValue({
          nightRegionUnitPrice: that.ParkCarChargeConfig[0].nightRegionUnitPrice
        })
        that.form.setFieldsValue({
          dayRegionFirstPrice: that.ParkCarChargeConfig[0].dayRegionFirstPrice
        })
        that.form.setFieldsValue({
          dayRegionFirstUnitMin: that.ParkCarChargeConfig[0].dayRegionFirstUnitMin
        })
        that.form.setFieldsValue({
          dayRegionMaxPrice: that.ParkCarChargeConfig[0].dayRegionMaxPrice
        })
        that.form.setFieldsValue({
          dayRegionUnitMin: that.ParkCarChargeConfig[0].dayRegionUnitMin
        })
        that.form.setFieldsValue({
          nightTimeRemainderMode: that.ParkCarChargeConfig[0].nightTimeRemainderMode
        })
        that.form.setFieldsValue({
          nightRegionFirstPrice: that.ParkCarChargeConfig[0].nightRegionFirstPrice
        })
        that.form.setFieldsValue({
          nightRegionFirstUnitMin: that.ParkCarChargeConfig[0].nightRegionFirstUnitMin
        })
        that.form.setFieldsValue({
          nightRegionMaxPrice: that.ParkCarChargeConfig[0].nightRegionMaxPrice
        })
        that.form.setFieldsValue({
          nightRegionUnitMin: that.ParkCarChargeConfig[0].nightRegionUnitMin
        })
        that.form.setFieldsValue({
          timeUnit: that.ParkCarChargeConfig[0].timeUnit
        })
        that.form.setFieldsValue({
          moneyUnit: that.ParkCarChargeConfig[0].moneyUnit
        })
        that.form.setFieldsValue({
          firstUnit: that.ParkCarChargeConfig[0].firstUnit
        })
        that.form.setFieldsValue({
          firstMoney: that.ParkCarChargeConfig[0].firstMoney
        })
        /*that.form.setFieldsValue({
          status: Number(that.ParkCarChargeConfig[0].status)
        })*/
        that.DayTimeStart = moment(that.ParkCarChargeConfig[0].dayRegionStartHour + ':' + that.ParkCarChargeConfig[
            0].dayRegionStartMin, 'HH:mm')
        that.NightTimeStart = moment(that.ParkCarChargeConfig[0].nightRegionStartHour + ':' + that
            .ParkCarChargeConfig[0].nightRegionStartMin, 'HH:mm')
        var TimeArray = this.DayTimeStart._i.split(':')
        this.form.setFieldsValue({
          dayRegionStartHour: TimeArray[0]
        })
        this.form.setFieldsValue({
          dayRegionStartMin: TimeArray[1]
        })
        TimeArray = this.NightTimeStart._i.split(':')
        this.form.setFieldsValue({
          nightRegionStartHour: TimeArray[0]
        })
        this.form.setFieldsValue({
          nightRegionStartMin: TimeArray[1]
        })
      } else {
        that.model.id = null
        that.freeTimeStatus = false
        that.ratesType = false
        that.DayTimeStart = moment('7:00', 'HH:mm')
        that.NightTimeStart = moment('19:00', 'HH:mm')

        that.form.setFieldsValue(that.form.setFieldsValue({
          carTypeId: value
        }))
        this.form.setFieldsValue({
          dayRegionStartHour: '7'
        })
        this.form.setFieldsValue({
          dayRegionStartMin: '0'
        })
        this.form.setFieldsValue({
          nightRegionStartHour: '19'
        })
        this.form.setFieldsValue({
          nightRegionStartMin: '0'
        })
        that.form.resetFields([
          'dayMoneyLimite',
          'status',
          'freeTime',
          'freeTimeStatus',
          'timeRemainderMode',
          'dayTimeRemainderMode',
          'dayRegionFirstPrice',
          'dayRegionFirstUnitMin',
          'dayRegionMaxPrice',
          'dayRegionUnitPrice',
          'dayRegionUnitMin',
          'nightTimeRemainderMode',
          'nightRegionFirstPrice',
          'nightRegionFirstUnitMin',
          'nightRegionMaxPrice',
          'nightRegionUnitPrice',
          'nightRegionUnitMin',
          'timeUnit',
          'moneyUnit',
          'firstUnit',
          'firstMoney',
        ])
      }
      this.confirmLoading = false

    },
    async loadData() {
      let that = this
      this.CarTypeSelect = []
      if (!this.url.CarTypeList) {
        this.$message.error("请设置url.CarTypeList!")
        return
      }
      let params = {}
      params.method = ""
      params.parkCode = that.parkCode
      //加载数据 若传入参数1则加载第一页的内容
      await getAction(this.url.CarTypeList,params).then((res) => {
        if (res.success) {
          var arr = [];
          res.result.forEach((car) => {
            arr.push({
              value: car.id,
              key: car.id,
              label: car.carTypeName
            })
          })
          that.CarTypeSelect = arr;
          if (that.CarTypeSelect.length !== 0) {
            that.form.setFieldsValue({
              carTypeId: that.CarTypeSelect[0].value
            })
          }
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
      })
      that.confirmLoading = false
    },
    CarSelect(value) {
      this.confirmLoading = true
      this.form.setFieldsValue({
        'carTypeId': value
      })
      this.loadParkData(value)
    },
    EditCancel() {
      this.DayTimeStart = moment('7:00', 'HH:mm')
      this.NightTimeStart = moment('19:00', 'HH:mm')
      this.freeTimeStatus = false
      this.ratesType = false
      this.form.resetFields(['dayMoneyLimite', 'status',
        'dayTimeRemainderMode',
        'dayRegionFirstPrice',
        'dayRegionFirstUnitMin',
        'dayRegionMaxPrice',
        'dayRegionUnitMin',
        'nightTimeRemainderMode',
        'nightRegionFirstPrice',
        'nightRegionFirstUnitMin',
        'nightRegionMaxPrice',
        'nightRegionUnitMin',
        'timeUnit',
        'moneyUnit',
        'firstUnit',
        'firstMoney',
        'timeRemainderMode'
      ])
    },
    onDayTimeChange(value) {
      this.form.setFieldsValue({
        dayRegionStartHour: value
      })
      this.form.setFieldsValue({
        dayRegionStartMin: '00'
      })
    },
    onNightTimeChange(value) {
      this.form.setFieldsValue({
        nightRegionStartHour: value
      })
      this.form.setFieldsValue({
        nightRegionStartMin: '00'
      })
    },
    freeTimeStatusChange(){
      this.freeTimeStatus =!this.freeTimeStatus
    },
    ratesTypeChange(){
      this.ratesType = !this.ratesType
    },
    onChangeStartTime(date, dateString) {
      this.queryParam.carEnterTime = dateString;
      this.queryParam.id = this.model.id;
    },
    onChangeEndTime(date, dateString) {
      this.queryParam.carOutTime = dateString;
      this.queryParam.id = this.model.id;
    },
    queryChargeFee() {
      if (this.queryParam.carOutTime === "") {
        return
      }
      if (this.queryParam.carEnterTime === "" && this.queryParam.carOutTime !== "") {
        this.$message.error("请选择开始时间");
        return
      }
      if (this.queryParam.carOutTime === "" && this.queryParam.carEnterTime !== "") {
        this.$message.error("请选择结束时间");
        return
      }
      if (this.queryParam.id === "" || this.queryParam.id === undefined || this.queryParam.id === null) {
        this.$message.error("请保存设置后重试");
        return
      }
      let params = Object.assign({}, this.queryParam);
      getAction(this.url.chargeFeeTest, params).then((res) => {
        if (res.success) {
          this.chargeFee = res.result / 100;
          this.confirmLoading = false
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
</style>
